package bai1;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Example2 {
	public static void inputEmployee(){
		Scanner ip=new Scanner(System.in);
		System.out.println("==============Them moi nhan vien=================");
		try{
			System.out.println("Nhap vao ten: ");
			String ten=ip.nextLine();
			while(ten.trim().equalsIgnoreCase("")){
				System.out.println("Chua nhap ten");
				ten=ip.nextLine();
			}
			System.out.println("Nhap ngay thang nam sinh");
			String date=ip.nextLine();
			while(date.trim().equalsIgnoreCase("")){
				System.out.println("Chua nhap ngay thang nam sinh");
				date=ip.nextLine();
			}
			if(!isValidDate(date)){
				System.out.println("Nhap khong dung dinh dang ! Nhap lai:");
				date=ip.nextLine();
			}
			System.out.println("Nhap vao dia chi");
			String dc=ip.nextLine();
			while(dc.trim().equalsIgnoreCase("")){
				System.out.println("Chua nhap dia chi");
				dc=ip.nextLine();
			}
			System.out.println("Nhap vao gioi tinh");
			String gt=ip.nextLine();
			while(gt.trim().equalsIgnoreCase("")){
				System.out.println("chua nhap gioi tinh");
				gt=ip.nextLine();
			}
			System.out.println("Nhap vao ngay bat dau lam viec");
			String startDate=ip.nextLine();
			while(startDate.trim().equalsIgnoreCase("")){
				System.out.println("Chua nhap ngay bat dau lam viec");
				startDate=ip.nextLine();
			}
			if(!isValidDate(startDate)){
				System.out.println("Nhap khong dung dinh dang ! Nhap lai:(dd/mm/yyyy");
				startDate=ip.nextLine();
			}
			System.out.println("Nhap chuc vu");
			System.out.println("1.Truong nhom");
			System.out.println("2.Truong du an");
			System.out.println("3.Nhan vien");
			int cv=ip.nextInt();
			System.out.println("Nhap tien luong co ban");
			int luong=ip.nextInt();
			int tienluong=luong+pcThamnien(thamnien(startDate))+pcChucvu(cv);
			String stt="|01";
			System.out.println("----------------------------------------------------------------------------------------------------");
			System.out.println("|Stt\t|Ho va ten\t|Chuc vu\t|Ngay thang nam sinh\t|Ngay lam viec\t|Tuoi\t|Tien luong");
			System.out.println("----------------------------------------------------------------------------------------------------");
			System.out.println(stt+" \t|"+ten + " \t|" + loaiCV(cv) + " \t|" + date + " \t\t|" +startDate+" \t|"+tuoi(date)+" \t|" +formatNumber(tienluong));
			System.out.println("----------------------------------------------------------------------------------------------------");
		}catch(InputMismatchException e){
			e.printStackTrace();
		}
	}
	public static String formatNumber(int number) {
           NumberFormat formatter = new DecimalFormat("###,###");
           String resp = formatter.format(number);
           resp = resp.replaceAll(",", " ");
           return resp;
    }
	public static int tuoi(String date){
		int age=0;
		Date today= new Date(System.currentTimeMillis());
		SimpleDateFormat timeFormat= new SimpleDateFormat("DD/MM/YYYY");
		String s=timeFormat.format(today.getTime());
		int year=Integer.parseInt(s.substring(6, 10));
		int month=Integer.parseInt(s.substring(3, 5));
		int day=Integer.parseInt(s.substring(0, 2));
		int yearDate=Integer.parseInt(date.substring(6, 10));
		int monthDate=Integer.parseInt(date.substring(3,5));
		int dayDate=Integer.parseInt(date.substring(0, 2));
		if(month>=monthDate){
			age=year-yearDate+1;
		}else{
			age=year-yearDate;
		}
		return age;	
	}
	public static int thamnien(String date){
		int kq=0;
		Date today= new Date(System.currentTimeMillis());
		SimpleDateFormat timeFormat= new SimpleDateFormat("DD/MM/YYYY");
		String s=timeFormat.format(today.getTime());
		String a=s.substring(6, 10);
		int year=Integer.parseInt(a);
		String b=s.substring(3, 5);
		int month=Integer.parseInt(b);
		String c=s.substring(0, 2);
		int day=Integer.parseInt(c);
		int yearDate=Integer.parseInt(date.substring(6, 10));
		int monthDate=Integer.parseInt(date.substring(3, 5));
		int dayDate=Integer.parseInt(date.substring(0, 2));
		if(day>=dayDate & month>=monthDate){
			kq=year-yearDate;
		}
		else{
			kq=year-yearDate-1;
		}
		return kq;
	}
	public static String loaiCV(int i){
		String cv="";
		if(i==1){
			cv="Truong nhom";
		}
		else if(i==2){
			cv="Truong du an";	
		}
		else{
			cv="Nhan vien";
		}
		return cv;
	}
	public static int pcThamnien(int i){
		int phucap=0;
		if(i>5){
			phucap=1000000;
		}
		else if(2<=i && i<5){
			phucap=500000;
		}
		else {
			phucap=0;
		}
		return phucap;	
	}
	public static int pcChucvu(int i){
		int pccv=0;
		if(i==1){
			pccv=500000;
		}
		else if(i==2){
			pccv=1000000;
		}
		else{
			pccv=0;
		}
		return pccv;
	}
	public static boolean isValidDate(String date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		try {
		dateFormat.setLenient(false);
		dateFormat.parse(date);
		return true;
		} catch (Exception e) {
		return false;
		}
		}
	public static void main(String args[]){
		//inputEmployee();
		Scanner sc=new Scanner(System.in);
		
		System.out.println("Nhap luong");
		int b=sc.nextInt();
		String a=formatNumber(b);
		System.out.println(a);
	}
}
